// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import Axios from 'axios'
import store from './store'
import Lodash from 'lodash'
import 'vant/lib/index.css';
import { Toast } from 'vant';

import i18n from './components/Common/i18n/i18n'

function getUrlKey (name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(window.location.href) || [, ""])[1].replace(/\+/g, '%20')) || null

}
let shopId = getUrlKey("shopId");

if (!shopId) {
  shopId = localStorage.getItem("shopId");
  if (!shopId) {
    shopId = 342;
  }
}
localStorage.setItem("shopId", shopId);

Vue.prototype.$SHOP_ID = shopId;

Axios.interceptors.request.use(
  config => {
    Toast.loading({
      duration: 0,       // 持续展示 toast
      forbidClick: true // 禁用背景点击
    })
    return config
  })

Axios.interceptors.response.use(
  response => {
    Toast.clear()
    return response
  },
  error => {
    Toast.clear()
    Toast.fail('网络超时')
    return Promise.reject(error)
  })
Vue.config.productionTip = false
Vue.prototype._ = Lodash
Vue.prototype.$http = Axios
Vue.prototype.$REQ_URL = 'http://hiroaus.huaqiaobang.com/index.php?'
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  components: { App },
  template: '<App/>'
})
